var first = 0; // when init, 1 means 竖屏, 2 means 横屏

function resize() {
    if (/Android|iPhone|iPod|iPad/i.test(navigator.userAgent)) {
        if (window.orientation === 180 || window.orientation === 0) {
//        alert('竖屏状态！');
            if (first === 0) {
                first = 1;
            }
            if (first === 1) {
                document.body.style.width = window.innerWidth + 'px';
                document.body.style.height = window.innerHeight + 'px';
            } else {
                document.body.style.width = window.height + 'px';
                document.body.style.height = window.width + 'px';
            }
        }
        if (window.orientation === 90 || window.orientation === -90) {
//        alert('横屏状态！');
            if (first === 0) {
                first = 2;
            }
            if (first === 1) {
                document.body.style.width = window.height + 'px';
                document.body.style.height = window.width + 'px';
            } else {
                document.body.style.width = window.innerHeight + 'px';
                document.body.style.height = window.innerWidth + 'px';
            }
        }
    } else {
        document.body.style.height = window.innerHeight + 'px';
    }
}

resize();